<script>
	export default {
		onLaunch: function() {
			// uni.setStorageSync("AppToken",
			// 	`Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjMyZmY4ZjllLTYxNDctNDg4Ny1iMDUzLWNmYThjYzQzMmE3ZiJ9.7CPMopzoK7kaMw2c3j9XF_1zh3UtDFfnOF5BwWLTAaxV1lmceUtVDIi9rKEw13OXGn6Xn-3FaPmUehjS1FXi_g`
			// )
			uni.loadFontFace({
				family: 'HarmonyOS',
				global: true,
				source: 'url("https://cdpresources.hobon.cc/procurement-mini-program/static/HarmonyOS_Sans_SC_Regular.woff")',
				success(e) {

				}
			})
		},
		onShow: function() {
			console.log('App Show')
			this.initPrintDevice()
			const _this = this;
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				if (res.hasUpdate) {
					uni.showModal({
						title: '更新提示',
						content: '已检测到新版本，是否下载并重启小程序？',
						success(res) {
							if (res.confirm) {
								_this.download(updateManager)
							} else {
								uni.showModal({
									title: '更新提示',
									content: '本次更新因改动较大，旧版本某些功能可能无法正常访问的哦~',
									showCancel: false,
									confirmText: "确认更新",
									success(res) {
										if (res.confirm) {
											_this.download(updateManager)
										}
									}
								});
							}
						}
					});
				}
			});
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			download(updateManager) {
				uni.showLoading({
					title: "下载中..."
				})
				updateManager.onUpdateReady(function(res) {
					uni.hideLoading();
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好，需重启应用',
						showCancel: false,
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					});

				});

				updateManager.onUpdateFailed(function(res) {
					uni.hideLoading();
					uni.showModal({
						title: '已有新版本',
						content: '请您删除小程序，重新搜索进入',
						showCancel: false,
						success(res) {

						}
					});
				});
			},
			initPrintDevice() {
				// let _this = this;
				// let deviceList = uni.getStorageSync("printList") || [];
				// let currentDevice = uni.getStorageSync("currentDevice");
				// if (deviceList.length) {
				// 	let cIndex = -1;
				// 	deviceList.forEach((item, index) => {
				// 		item.connected = false;
				// 		if (currentDevice && currentDevice.deviceId === item.deviceId) {
				// 			cIndex = index;
				// 		}
				// 	})
				// 	if (cIndex > -1) {
				// 		setTimeout(() => {
				// 			_this.$print.connectDevice(currentDevice, 0, false)
				// 		}, 1000)
				// 	}
				// }
				// uni.openBluetoothAdapter({
				// 	complete: (res) => {
				// 		uni.onBLEConnectionStateChange(function(ress) {
				// 			if (!ress.connected) {
				// 				_this.$print.closeBLEConnection(ress.deviceId, 0)
				// 				deviceList.forEach(item => {
				// 					item.connected = false;
				// 				})
				// 				_this.$store.commit('setStorageList', deviceList);
				// 			}
				// 		})
				// 	}
				// })

			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import './global.css';

	html,
	body {
		background-color: #E6EDF2;
		font-family: 'HarmonyOS';
	}

	view,
	text {
		font-family: 'HarmonyOS';
	}

	page {
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	scroll-view::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}

	::-webkit-scrollbar {
		display: none;
	}
</style>